package org.veloxbot.api.wrappers;

/**
 * @author Velox
 */
public class VectorPath {

	private VectorTile[] tiles;

	/**
	 * Constructs a VectorPath of the given tiles.
	 *
	 * @param tiles The tiles of the path to construct.
	 */
	public VectorPath(final VectorTile[] tiles) {
		this.tiles = tiles;
	}

	/**
	 * Walks the given path.
	 *
	 * @return <t>true</t> if the path was successfully walked, otherwise <t>false</t>.
	 */
	public boolean traverse() {
		for (final VectorTile vectorTile : tiles) {
			if (!vectorTile.clickOnMap()) {
				return false;
			}
		}
		return true;
	}

	/**
	 * Constructs an reversed path of the current path.
	 *
	 * @return A reversed path of the current path.
	 */
	public VectorPath reverse() {
		final VectorTile[] tiles = new VectorTile[this.tiles.length];
		for (int i = this.tiles.length - 1; i >= 0; i--) {
			final VectorTile tile = this.tiles[i];
			if (tile != null) {
				tiles[i] = this.tiles[i];
			}
		}
		return new VectorPath(tiles);
	}
}